package com.kw.drug.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.kw.drug.common.ResultMapUtil;
import com.kw.drug.entity.Billinfo;
import com.kw.drug.service.BillinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Controller
@RequestMapping("/billinfo")
public class BillinfoController {
    @Autowired
    BillinfoService billinfoService;

    @RequestMapping()
    public String billinfoIndex() {
        return "billinfo";
    }

    /**
     * 分页查询账单信息列表
     */
    @RequestMapping("/billinfoQueryPage")
    @ResponseBody
    public Object billinfoQueryPage(String param, @RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "10") int pageSize) {
        try {
            IPage<Billinfo> iPage = billinfoService.selectBillinfoPage(pageNum, pageSize, param);
            return ResultMapUtil.getHashMapMysqlPage(iPage);
        } catch (Exception e) {
            return ResultMapUtil.getHashMapException(e);
        }
    }

    /**
     * 转向账单信息新增页面
     */
    @RequestMapping("/billinfoPage")
    public String billinfoPage() {
        return "billinfoPage";
    }

    /**
     * 添加一个账单信息
     */
    @RequestMapping("/billinfoAdd")
    @ResponseBody
    public Map billinfoAdd(Billinfo billinfo) {
        try {
            int i = billinfoService.addBillinfo(billinfo);
            return ResultMapUtil.getHashMapSave(i);
        } catch (Exception e) {
            return ResultMapUtil.getHashMapException(e);
        }
    }

    /**
     * 转向账单信息编辑页面
     */
    @RequestMapping("/billinfoQueryById")
    public String billinfoQueryById(@RequestParam(name = "id", required = true) Integer id, Model model) {
        Billinfo billinfo = billinfoService.queryBillinfoById(id);
        model.addAttribute("obj", billinfo);
        return "billinfoPage";
    }

    /**
     * 修改一个账单信息
     */
    @RequestMapping("/billinfoEdit")
    @ResponseBody
    public Map billinfoEdit(Billinfo billinfo) {
        try {
            int i = billinfoService.editBillinfo(billinfo);
            return ResultMapUtil.getHashMapSave(i);
        } catch (Exception e) {
            return ResultMapUtil.getHashMapException(e);
        }
    }

    /**
     * 删除记录
     */
    @RequestMapping("/billinfoDelById")
    @ResponseBody
    public Map deleteSaleinfo(Integer id) {
        try {
            int i = billinfoService.delBillinfoById(id);
            return ResultMapUtil.getHashMapSave(i);
        } catch (Exception e) {
            return ResultMapUtil.getHashMapException(e);
        }
    }


}







